{extend name="public:base"/}


{block name="title"}新增权限{/block}
{block name="style"}{/block}

{block name="main"}

<section class="content">
    <div class="row">

        <div class="col-md-12">

            <div class="row">
                <div class="col-lg-12">
                    <div class="box">
                        <div class="box-header with-border">
                            <h3 class="box-title">新增权限</h3>
                        </div>
                        <form  id="pt_form" method="post">
                            <div class="box-body">

                                <div class="clearfix"></div>

                                <div class="form-group required">
                                    <div class='col-sm-2 text-right'>
                                        <label class="control-label Validform_label" for="pri_name">权限名称</label>
                                    </div>
                                    <div class='col-sm-10'>
                                        <input type="text" id="pri_name" class="form-control" name="pri_name" placeholder="权限名称" datatype="*">
                                        <div class="help-block"></div>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <div class='col-sm-2 text-right'>
                                        <label class="control-label" for="article-cate_id">父级权限</label>
                                    </div>
                                    <div class='col-sm-10'>
                                        <div class="kv-plugin-loading loading-article-cate_id">&nbsp;</div>
                                        <select id="article-cate_id" class="form-control" name="parent_id"
                                                data-s2-options="s2options_d6851687"
                                                data-krajee-select2="select2_138e92d5"
                                                style="width: 1px; height: 1px; visibility: hidden;">

                                            <option value="0">顶级按钮</option>
                                            <?php if(!empty($privilegeData)){ foreach($privilegeData as $pri){?>
                                            <option value="<?=$pri['id']?>"><?=str_repeat('|-----',$pri['lev']).$pri['pri_name']?></option>
                                            <?php }}?>
                                        </select>
                                        <div class="help-block"></div>
                                    </div>
                                </div>

                                <div class="form-group required">
                                    <div class='col-sm-2 text-right'>
                                        <label class="control-label Validform_label" for="module_name">模块名称</label>
                                    </div>
                                    <div class='col-sm-10'>
                                        <input type="text" id="module_name" class="form-control" placeholder="模块名称" name="module_name" datatype="*">
                                        <div class="help-block"></div>
                                    </div>
                                </div>

                                <div class="form-group required">
                                    <div class='col-sm-2 text-right'>
                                        <label class="control-label" for="controller_name">控制器名称</label>
                                    </div>
                                    <div class='col-sm-10'>
                                        <input type="text" id="controller_name" class="form-control" placeholder="控制器名称" name="controller_name" value="" datatype="*">
                                        <div class="help-block"></div>
                                    </div>
                                </div>


                                <div class="form-group required">
                                    <div class='col-sm-2 text-right'>
                                        <label class="control-label" for="controller_name">方法名称</label>
                                    </div>
                                    <div class='col-sm-10'>
                                        <input type="text" id="action_name" class="form-control" placeholder="方法名称" name="action_name" value="" datatype="*">
                                        <div class="help-block"></div>
                                    </div>
                                </div>


                                <div class="form-group">
                                    <div class='col-sm-2 text-right'>
                                        <label class="control-label" for="parameter">参数</label>
                                    </div>
                                    <div class='col-sm-10'>
                                        <input type="text" id="parameter" class="form-control" placeholder="参数,举例：a/1/b/2" name="parameter" value="">
                                        <div class="help-block"></div>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <div class='col-sm-2 text-right'>
                                        <label class="control-label" for="pri_icon">图标</label>
                                    </div>
                                    <div class='col-sm-10'>
                                        <input type="text" id="pri_icon" class="form-control" placeholder="图标" name="pri_icon" value="">
                                        <div class="help-block"></div>
                                    </div>
                                </div>

                                <div class="form-group">
                                    <div class='col-sm-2 text-right'>
                                        <label class="control-label" for="pri_order">排序</label>
                                    </div>
                                    <div class='col-sm-10'>
                                        <input type="text" id="pri_order" class="form-control" placeholder="方法名称" name="pri_order" value="0">
                                        <div class="help-block"></div>
                                    </div>
                                </div>

                                <div class="form-group required">
                                    <div class='col-sm-2 text-right'><label class="control-label">是否菜单</label></div>
                                    <div class='col-sm-10'>
                                        <input type="hidden" name="Article[status]" value="">
                                        <div id="article-status" role="radiogroup">
                                            <label>
                                                <input type="radio" name="is_menu" value="1" checked>
                                                菜单
                                            </label>

                                            <label>
                                                <input type="radio" name="is_menu" value="0">
                                                方法
                                            </label>
                                        </div>
                                        <div class="help-block"></div>
                                    </div>
                                </div>
                            </div>
                            <div class="box-footer text-center">
                                <button class="btn btn-primary" type="submit">保存</button>
                                <span class="btn btn-white" onclick="history.go(-1)">返回</span>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>
{/block}

{block name="js"}
<script>
    jQuery(function ($) {
        window.select2_138e92d5 = {
            "allowClear": true,
            "theme": "krajee",
            "width": "100%",
            "placeholder": "请选择",
            "language": "zh-CN"
        };

        if (jQuery('#article-cate_id').data('select2')) {
            jQuery('#article-cate_id').select2('destroy');
        }
        jQuery.when(jQuery('#article-cate_id').select2(select2_138e92d5)).done(initS2Loading('article-cate_id', 's2options_d6851687'));
    });


    var validate = $("#pt_form").Validform({
        tiptype: function(msg,o,cssctl){
            if(o.type == 3){
                toastr.error(msg);
                return false;
            }
        },
        datatype:{
            /*
            'need2':function(gets,obj,curform,regxp){

                var need=2,
                    numselected=curform.find("input[name='"+obj.attr("name")+"']:checked").length;
                if(numselected >= need){
                    $('.pri_id').find('.Validform-checkbox').removeClass('Validform_wrong').addClass('Validform_right');
                    $('.pri_id').find('.Validform-checkbox').text("通过验证");
                    return true;
                }else{
                    $('.pri_id').find('.Validform-checkbox').addClass('Validform_wrong');
                    $('.pri_id').find('.Validform-checkbox').text("请至少选择"+need+"项！");
                    return false;
                }
            },
            */
        },
        tipSweep:true, //是否失去焦点就验证
        postonce:true, //表单只提交一次
        ajaxPost:true, //异步提交表单
        beforeSubmit:function(curform){
            layer.load(2);
        },
        callback:function(data){
            if(data.code==300){
                layer.closeAll();
                toastr.error(data.msg);
                return false;
            }else{
                window.location.href= "<?=url('@admin/privilege/index')?>";
                return false;
            }
        }
    });

</script>
{/block}